<template>
  <div class="cla_login">
    <!-- <div class="cla_login"> -->
    <div class="login_box">
      <!-- 头像logo区域 -->
      <div class="login_logo">
        <img src="../assets/logo.png" />
      </div>
      <!-- 表单操作区域 -->
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="loginFormRules"
        label-width="0px"
        class="login_form"
      >
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user" value=""></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            v-model="loginForm.password"
            prefix-icon="iconfont icon-3702mima"
          ></el-input>
        </el-form-item>
        <el-form-item class="login_form_btn">
          <el-button type="primary" @click="okLoginForm" round>确定</el-button>
          <el-button type="info" @click="resetLoginForm()" round>重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- </div> -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      loginForm: {
        username: "admin",
        password: "123456"
      },
      loginFormRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 8, message: "长度在 6 到 8 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    resetLoginForm() {
      //   alert("我要重置表单");
      console.log(this);
      this.$refs.loginFormRef.resetFields();
    },
    okLoginForm() {
      this.$refs.loginFormRef.validate(valid => {
        console.log(valid);
        if (!valid) {
          return;
        }
        console.log("===开始请求=>");
        this.$httpReq
          .post("login", this.loginForm)
          .then(res => {
            console.log("===res=>" + JSON.stringify(res));
            var msg = res.meta.msg;
            console.log("===msg=>" + msg);
            if (res.meta.status == 200) {
              this.$message.success("登录成功");
              window.sessionStorage.setItem("token",res.data.token);
              this.$router.push("/")
               console.log("===token=>" + res.data.token);
            } else {
              this.$message.error(msg);
            }
          })
          .catch(error => {
            console.log("==error=s=>" + JSON.stringify(error));
          });
      });
    }
  }
};
</script>
<style scoped>
.cla_login {
  width: 100%;
  height: 100%;
  background: #2b4b6b;
}
.login_box {
  width: 450px;
  height: 300px;
  background: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.input {
  width: 200px;
}
.login_logo {
  width: 110px;
  height: 110px;
  border: 1px solid #eee;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
}
img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #e5e5e5;
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.login_form_btn {
  display: flex;
  justify-content: flex-end;
}
</style>